package com.wy.entity;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.hibernate.annotations.GenericGenerator;

@Entity
@Table(name="book", catalog="bookmanager")
public class Book {

	private Integer id;
	private String name;
//	private String author;
//	private String bookType;
	private Author author;
	private BookType bookType;
	private String introduce;
	private String webName;
	private String catalogURL;
	private String xmlTargetPath;
	private String xmlMD5;
//	private Set<Chapter> chapters = new HashSet<Chapter>();
//	private List<Chapter> chapterList = new ArrayList<Chapter>();
	
	public Book(){
		
	}
	public Book(String name,Author author,BookType bookType,String introduce,
			String webName,String catalogURL,Set<Chapter> chapters,String xmlTargetPath){
		this.name = name;
		this.author = author;
		this.bookType = bookType;
		this.webName = webName;
		this.catalogURL = catalogURL;
		this.xmlTargetPath = xmlTargetPath;
		this.introduce = introduce;
	}
	
	@GenericGenerator(name="generator", strategy="increment")
	@Id
	@GeneratedValue(generator="generator")
	@Column(name="id", unique=true, nullable=false)
	public Integer getId() {
		return id;
	}
	public void setId(Integer id) {
		this.id = id;
	}
	
	@Column(name="name", length=50)
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	
//	@ManyToOne(fetch=FetchType.LAZY)
//	@JoinColumn(name="authorId")
//	public Author getAuthor() {
//		return author;
//	}
//	public void setAuthor(Author author) {
//		this.author = author;
//	}
	@ManyToOne(fetch=FetchType.LAZY)
    @JoinColumn(name="authorId")
	public Author getAuthor() {
	    return this.author;
	}
	public void setAuthor(Author author) {
	    this.author = author;
	}
	
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="bookTypeId")
	public BookType getBookType() {
		return bookType;
	}
	public void setBookType(BookType bookType) {
		this.bookType = bookType;
	}
	
	@Column(name="webName", length=30)
	public String getWebName() {
		return webName;
	}
	public void setWebName(String webName) {
		this.webName = webName;
	}
	
	@Column(name="catalogURL", length=200)
	public String getCatalogURL() {
		return catalogURL;
	}
	public void setCatalogURL(String catalogURL) {
		this.catalogURL = catalogURL;
	}
	
	@Column(name="xmlTargetPath", length=100)
	public String getXmlTargetPath() {
		return xmlTargetPath;
	}
	public void setXmlTargetPath(String xmlTargetPath) {
		this.xmlTargetPath = xmlTargetPath;
	}
	
	@Column(name="xmlMD5", length=50)
	public String getXmlMD5() {
		return xmlMD5;
	}
	public void setXmlMD5(String xmlMD5) {
		this.xmlMD5 = xmlMD5;
	}
	
	@Column(name="introduce")
	public String getIntroduce() {
		return introduce;
	}
	public void setIntroduce(String introduce) {
		this.introduce = introduce;
	}
	
//	public Set<Chapter> getChapters() {
//		return chapters;
//	}
//	public void setChapters(Set<Chapter> chapters) {
//		this.chapters = chapters;
//	}
//	public List<Chapter> getChapterList() {
//		return chapterList;
//	}
//	public void setChapterList(List<Chapter> chapterList) {
//		this.chapterList = chapterList;
//	}
	
}
